<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>订单列表</title>
    <link rel="stylesheet" type="text/css" href="/static/jquery-easyui-1.5.5.4/themes/metro/easyui.css"/>
    <link rel="stylesheet" type="text/css" href="/static/jquery-easyui-1.5.5.4/themes/icon.css"/>
    <script type="text/javascript" src="/static/jquery-easyui-1.5.5.4/jquery.min.js"></script>
    <script type="text/javascript" src="/static/jquery-easyui-1.5.5.4/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="/static/jquery-easyui-1.5.5.4/locale/easyui-lang-zh_CN.js"></script>
    <script type="text/javascript" src="/static/js/common/public.js"></script>
    <script>
        var orderId = 0;

        function testAddSubPage(title,url) {
        localStorage.lastname="Smith";

            var jq = top.jQuery;
            if (jq("#tabs").tabs('exists', title)){
                jq("#tabs").tabs('select', title);
            } else {
                  var content = '<iframe scrolling="auto" frameborder="0"  src="'+url+'" style="width:100%;height:100%;"></iframe>';
                   jq("#tabs").tabs('add',{
                          title:title,
                          content:content,
                          closable:true
                   });
             }
        }

        function openOrderAddDialog(){
            testAddSubPage("添加订单", "/order/addOrder.html");
        }
        function openOrderModifyDialog(){
           var selectdRows = $("#dg").datagrid("getSelections");
           if(selectdRows.length !=1){
                $.messager.alert("系统提示", "请选择一条要修改的数据");
                return;
           }
           var row = selectdRows[0];
           orderId = row.orderId;
           localStorage.orderId = orderId;
           testAddSubPage("修改订单", "/order/modifyOrder.html");
        }

        function ForOrderStatusName(val,row) {

            var orderStatusName="";//0待确定 1已确定  2已收货  3已取消  4已完成  5已作废
            if(row.orderStatus==0){
                orderStatusName="待确定";
            }
            if(row.orderStatus==1){
                orderStatusName="已完成";
            }
            if(row.orderStatus==2){
                orderStatusName="驳回";
            }

            return orderStatusName;
        }

        function searchOrder() {
            $("#dg").datagrid('load', {
                "orderSN": $("#orderSN").val(),
                "consignee": $("#consignee").val(),
                "orderStatus": $("#orderStatus").val()=="100"?null:$("#orderStatus").val(),
                "addTimeStart": $("#s_bPurchaseDate").val(),
                "addTimeEnd": $("#s_ePurchaseDate").val(),
                "goodsList[0].id": $("#orderStatus").val()=="100"?null:$("#orderStatus").val()

            });

        }

        function timeFormat(row){
            return date("Y-m-d", row.addTime);
        }


        function flowBtn(){
           var selectdRows = $("#dg").datagrid("getSelections");
           if(selectdRows.length !=1){
                $.messager.alert("系统提示", "请选择一条要修改的数据");
                return;
           }
           var row = selectdRows[0];
           orderId = row.orderId;
           $("#orderId").val(orderId);
           $("#orderDetail").dialog("open").dialog("setTitle", "订单类型");
           $("#orderDetailForm").form("load", row);

         }


        function UpdateOrderStatus(){
           if(orderId ==0){
                $.messager.alert("系统提示", "订单id为空");
                return;
           }
           $("#ordersp").dialog("open").dialog("setTitle", "订单类型");

        }

        function modifyOrderStatus(){
           var url ="/admin/order/approve";
            $("#orderspForm").form("submit", {
                url : url,
                onSubmit:function () {
                    return $(this).form("validate");
                },
                success: function (result){

                   // var result = eval('('+result+')');
                    if(result.success){
                        $.messager.alert("系统提示", "审批成功！");
                        $('#orderDetail').dialog('close');
                         $('#ordersp').dialog('close');
                    }else{
                        $.messager.alert("系统提示", "审批成功");
                    }
                    $('#orderDetail').dialog('close');
                     $('#ordersp').dialog('close');
                   $("#dg").datagrid("reload");
                }
            });
        }

        function deleteOrder(){
                 var url ="/admin/order/approve";
                 var data = {orderId: orderId,orderStatus:$("#orderType").val()};
                 console.log(data);

                 return;
                $.post(url, {orderId: ids}, function (result) {
                    if (result.success) {
                        $.messager.alert("系统提示", "数据已成功删除！");
                        $("#dg").datagrid("reload");
                    } else {
                        $.messager.alert("系统提示", result.errorInfo);
                    }
                }, "json");

        }

        function searchOrderDetail(){
           var selectdRows = $("#dg").datagrid("getSelections");
           if(selectdRows.length !=1){
                $.messager.alert("系统提示", "请选择一条要查看的数据");
                return;
           }
           var row = selectdRows[0];
           orderId = row.orderId;
            localStorage.orderId = orderId;
            localStorage.isLeader = true;
            testAddSubPage("查看订单详情", "/order/orderDetail.html");
        }


    </script>
</head>
<body style="margin: 1px">
<table id="dg" title="订单列表" class="easyui-datagrid"
       fitColumns="true" pagination="true" rownumbers="true"
       url="/admin/order/list" method="get" fit="true" toolbar="#tb" singleSelect="true">
    <thead>
    <th field="cb" checkbox="true" align="center"></th>
    <th field="orderSN" width="100" align="center">订单编号</th>
    <th field="customerName" width="100" align="center">客户</th>
    <th field="orderAmount" width="50" align="center">总金额</th>
    <th field="orderStatusName" width="50" align="center" formatter="ForOrderStatusName">订单状态</th>
    <th field="addTime" width="150" align="center">下单时间</th>
    <th field="remarks" width="150" align="center">备注</th>
    <th field="start" hidden />
    <th field="end" hidden />
    <th field="goodsList[0].id" hidden />

    </thead>
</table>

<div id="tb">
    <div>
        <a href="javascript:openOrderAddDialog()"  class="easyui-linkbutton" iconCls="icon-add" plain="true">添加</a>
        <a href="javascript:openOrderModifyDialog()" class="easyui-linkbutton" iconCls="icon-edit" plain="true">修改</a>
        <!--<a href="javascript:deleteOrder()" class="easyui-linkbutton" iconCls="icon-remove" plain="true">删除</a>-->
        <a href="javascript:searchOrderDetail()" class="easyui-linkbutton" iconCls="icon-search" plain="true">查看详情</a>
        <a href="javascript:flowBtn()" class="easyui-linkbutton" iconCls="icon-sum" plain="true">流程管理</a>
    </div>
    <div>
        &nbsp;收货人：&nbsp;<input type="text" id="consignee" size="20" onkeydown="if(event.keyCode==13) searchOrder()"/>
        &nbsp;订单号：&nbsp;<input type="text" id="orderSN" size="20" onkeydown="if(event.keyCode==13) searchOrder()"/>
        &nbsp;状态：&nbsp;<select id="orderStatus" class="easyui-combobox" name="dept" style="width:100px;" data-options="editable:false,panelHeight:'auto'">
            <option value="100">选择状态</option>
            <option value="0">待确定</option>
            <option value="1">已完成</option>
            <option value="2">驳回</option>
       </select>
        &nbsp;&nbsp;&nbsp;日期：&nbsp;
        <input id="s_bPurchaseDate" name="addTimeStart" class="easyui-datebox" editable=false style="width:100px"/>
        &nbsp;&nbsp;-&nbsp;&nbsp;
        <input id="s_ePurchaseDate" name="addTimeEnd" class="easyui-datebox" editable=false style="width:100px"/>
        <a href="javascript:searchOrder()" class="easyui-linkbutton" iconCls="icon-search" plain="true">搜索</a>
    </div>
</div>

<div id="orderDetail" class="easyui-dialog" style="width: 600px;height: 400px;padding: 20px"
     closed="true" data-options="
				iconCls: 'icon-save',
				buttons: '#dlg-buttons',
				modal:true,
				onClose:function(){}">
    <form id="orderDetailForm" method="post">
        <table cellspacing="8px">
            <tr>
                <td>商品订单号：</td>
                <td>
                    <input type="text"  name="orderSN" class="easyui-validatebox"
                           style="width: 250px" readonly/>
                </td>
            </tr>
            <tr>
                <td>客户：</td>
                <td>
                    <input type="text"  name="customerName" class="easyui-validatebox"
                           style="width: 250px" readonly/>
                </td>
            </tr>
            <tr>
                <td>总金额：</td>
                <td>
                    <input type="text"  name="orderAmount" class="easyui-validatebox"
                           style="width: 250px" readonly/>
                </td>
            </tr>
            <tr>
                <td>备注：</td>
                <td>
                    <input type="text"  name="remarks" class="easyui-validatebox"
                           style="width: 250px" readonly/>
                </td>
            </tr>
        </table>
    </form>
</div>

<div id="dlg-buttons">
    <a href="javascript:void(0)" class="easyui-linkbutton" onclick="UpdateOrderStatus()">审批</a>
    <a href="javascript:void(0)" class="easyui-linkbutton" onclick="javascript:$('#orderDetail').dialog('close')">关闭</a>
</div>

<div id="ordersp" class="easyui-dialog" style="width: 600px;height: 400px;padding: 20px"
     closed="true" data-options="
				iconCls: 'icon-save',
				buttons: '#dlg-buttons1',
				modal:true,
				onClose:function(){}">
    <form id="orderspForm" method="post">
        <table cellspacing="8px">
            <tr>
                <td>审批类型：</td>
                <td>
                    <select id="cc" class="easyui-combobox" name="orderStatus" style="width:200px;">
                        <option value="1">通过</option>
                        <option value="2">驳回</option>
                    </select>
                    <input type="hidden" name="orderId"  id="orderId" />
                </td>
            </tr>
        </table>
    </form>
</div>
<div id="dlg-buttons1">
    <a href="javascript:void(0)" class="easyui-linkbutton" onclick="modifyOrderStatus()">提交</a>
    <a href="javascript:void(0)" class="easyui-linkbutton" onclick="javascript:$('#ordersp').dialog('close')">关闭</a>
</div>

</body>
</html>